package jvm.ref;

import java.util.WeakHashMap;

/**
 * 弱HashMap
 * @author jiangwz
 * @create 2019/9/17.
 */
public class WeakHashMapDemo {

    public static void main(String[] args){

        WeakHashMap<Integer, Object> hashMap = new WeakHashMap<>();
        Integer key = new Integer(2);
//        Integer key = 2; //这个不行,必须要对象
        String value = "HashMap";
        hashMap.put(key,value);
        System.out.println(hashMap);

        key = null;
        System.gc();
        System.out.println(hashMap);

    }

}
